﻿/**********************************************************************/
/*                                                                    */
/*                   embDocumentInhalator                             */
/*             http://embdocumentinhalator.codeplex.com/              */
/*                                                                    */
/*               (c) Copyright 2010 Ilija Injac         .             */
/*                                                                    */
/*  This source is subject to the CDDL License                        */
/*  http://embdocumentinhalator.codeplex.com/license                  */
/*                                                                    */
/*                                                                    */
/**********************************************************************/
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.UserCode;
using Microsoft.SharePoint.Security;
using System.Security.Permissions;
using System.Security;
using Microsoft.SharePoint;
using System.Web.Hosting;
using WIA;
using embWIAScan;
using System.Collections;

[assembly: AllowPartiallyTrustedCallers]
namespace embSPScanExpert.Proxy
{

    /// <summary>
    /// Enumerates all Scanners attached to the server.
    /// </summary>
    /// This element was inserted by injac on machine PLATINCHECKER.
    /// 29.01.2011,20:50
    public class EnumerateScanners : SPProxyOperation
    {
        /// <summary>
        /// Executes the EnumareteScanners SPProxyOperation.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        /// This element was inserted by injac on machine PLATINCHECKER.
        /// 29.01.2011,20:50
        public override object Execute(SPProxyOperationArgs args)
        {
            if (args != null)
            {
                
                ScannerEnumArgs arguments = args as ScannerEnumArgs;
                arguments.DeviceNames = EnumerateDevices();
                return arguments.DeviceNames;
            }
            else
            {
                return null;
            }

        }

        /// <summary>
        /// Enumerates the devices.
        /// </summary>
        /// <returns></returns>
        /// This element was inserted by injac on machine PLATINCHECKER.
        /// 29.01.2011,20:51
        public ArrayList EnumerateDevices()
        {
            DeviceManager manager = new DeviceManager();
            ArrayList deviceNames = new ArrayList();

            foreach (DeviceInfo devInfo in manager.DeviceInfos)
            {
                if (devInfo.Type == WIA.WiaDeviceType.ScannerDeviceType)
                {
                    {
                        foreach (WIA.Property p in devInfo.Properties)
                        {

                            if (p.Name == "Name")
                            {
                                deviceNames.Add(((WIA.IProperty)p).get_Value().ToString());
                            }
                        }
                    }
                }
            }
            return deviceNames;
        }

    }
}
